var e = require;
var t = module;
var n = exports;
var o,
    i =
        (this && this.__extends) ||
        ((o = function (e, t) {
            return (o =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var n in t) Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
                })(e, t);
        }),
        function (e, t) {
            var n;
            {
                function n() {
                    this.constructor = e;
                }
                o(e, t), (e.prototype = null === t ? Object.create(t) : ((n.prototype = t.prototype), new n()));
            }
        }),
    r =
        (this && this.__decorate) ||
        function (e, t, n, o) {
            var i,
                r = arguments.length,
                a = r < 3 ? t : null === o ? (o = Object.getOwnPropertyDescriptor(t, n)) : o;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(e, t, n, o);
            else
                for (var s = e.length - 1; 0 <= s; s--)
                    (i = e[s]) && (a = (r < 3 ? i(a) : 3 < r ? i(t, n, a) : i(t, n)) || a);
            return 3 < r && a && Object.defineProperty(t, n, a), a;
        },
    a =
        (this && this.__awaiter) ||
        function (e, a, s, c) {
            return new (s = s || Promise)(function (n, t) {
                function o(e) {
                    try {
                        r(c.next(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function i(e) {
                    try {
                        r(c.throw(e));
                    } catch (e) {
                        t(e);
                    }
                }
                function r(e) {
                    var t;
                    e.done
                        ? n(e.value)
                        : ((t = e.value) instanceof s
                              ? t
                              : new s(function (e) {
                                    e(t);
                                })
                          ).then(o, i);
                }
                r((c = c.apply(e, a || [])).next());
            });
        },
    s =
        (this && this.__generator) ||
        function (n, o) {
            var i,
                r,
                a,
                s = {
                    label: 0,
                    sent: function () {
                        if ((1, 1 & a[0])) throw a[1];
                        return a[1];
                    },
                    trys: [],
                    ops: []
                },
                e = {next: t(0), throw: t(1), return: t(2)};
            return (
                "function" == typeof Symbol &&
                    (e[Symbol.iterator] = function () {
                        return this;
                    }),
                e
            );
            function t(t) {
                return function (e) {
                    return (function (t) {
                        if (i) throw new TypeError("Generator is already executing.");
                        for (; s; )
                            try {
                                if (
                                    ((i = 1),
                                    r &&
                                        (a =
                                            2 & t[0]
                                                ? r.return
                                                : t[0]
                                                ? r.throw || ((a = r.return) && a.call(r), 0)
                                                : r.next) &&
                                        !(a = a.call(r, t[1])).done)
                                )
                                    return a;
                                switch (((r = 0), (t = a ? [2 & t[0], a.value] : t)[0])) {
                                    case 0:
                                    case 1:
                                        a = t;
                                        break;
                                    case 4:
                                        return s.label++, {value: t[1], done: !1};
                                    case 5:
                                        s.label++, (r = t[1]), (t = [0]);
                                        continue;
                                    case 7:
                                        (t = s.ops.pop()), s.trys.pop();
                                        continue;
                                    default:
                                        if (
                                            !(a = 0 < (a = s.trys).length && a[a.length - 1]) &&
                                            (6 === t[0] || 2 === t[0])
                                        ) {
                                            s = 0;
                                            continue;
                                        }
                                        if (3 === t[0] && (!a || (t[1] > a[0] && t[1] < a[3]))) {
                                            s.label = t[1];
                                            break;
                                        }
                                        if (6 === t[0] && s.label < a[1]) {
                                            (s.label = a[1]), (a = t);
                                            break;
                                        }
                                        if (a && s.label < a[2]) {
                                            (s.label = a[2]), s.ops.push(t);
                                            break;
                                        }
                                        a[2] && s.ops.pop(), s.trys.pop();
                                        continue;
                                }
                                t = o.call(n, s);
                            } catch (e) {
                                (t = [6, e]), (r = 0);
                            } finally {
                                i = a = 0;
                            }
                        if (5 & t[0]) throw t[1];
                        return {value: t[0] ? t[1] : void 0, done: !0};
                    })([t, e]);
                };
            }
        };
Object.defineProperty(n, "__esModule", {value: !0}), (n.GuideManager = n.GuideStep = void 0);
var c,
    l = e("index"),
    u = e("events"),
    p = e("guide-node"),
    h = e("player-coin"),
    d = e("player-info"),
    f = cc._decorator,
    m = f.ccclass,
    t = (f.property, f.menu),
    e = f.disallowMultiple;
((f = c = n.GuideStep || (n.GuideStep = {}))[(f.NONE = 0)] = "NONE"),
    (f[(f.choose = 2)] = "choose"),
    (f[(f.place = 4)] = "place"),
    (f[(f.merge = 8)] = "merge"),
    (f[(f.deal = 16)] = "deal"),
    (f[(f.choose1 = 32)] = "choose1"),
    (f[(f.place1 = 64)] = "place1"),
    (f[(f.choose2 = 128)] = "choose2"),
    (f[(f.place2 = 256)] = "place2"),
    (f[(f.merge1 = 512)] = "merge1"),
    (f[(f.target = 1024)] = "target"),
    (f[(f.deal1 = 2048)] = "deal1");
var y,
    g,
    e =
        ((y = cc.Component),
        i(v, y),
        ((g = v).prototype.onLoad = function () {
            g.ins = this;
        }),
        (v.prototype.setIsNeedMergeWeakGuide = function (e) {
            (this.isNeedMergeWeakGuide = e), this.isNeedMergeWeakGuide || this.hideHand();
        }),
        (v.prototype.getIsNeedMergeWeakGuide = function () {
            return this.isNeedMergeWeakGuide;
        }),
        (v.prototype.setIsNeedDealWeakGuide = function (e) {
            (this.isNeedDealWeakGuide = e), this.isNeedDealWeakGuide || this.hideHand();
        }),
        (v.prototype.getIsNeedDealWeakGuide = function () {
            return this.isNeedDealWeakGuide;
        }),
        (v.prototype.setIsGuide = function (e) {
            this.isGuide = e;
        }),
        (v.prototype.getIsGuide = function () {
            return this.isGuide;
        }),
        (v.prototype.setIsNeedCheck = function (e) {
            this.isNeedCheck = e;
        }),
        (v.prototype.loadGuideNode = function (n) {
            return a(this, void 0, void 0, function () {
                var t;
                return s(this, function (e) {
                    switch (e.label) {
                        case 0:
                            return [4, l.ResUtil.loadPrefab("prefab/prefab/guide-node")];
                        case 1:
                            return (
                                (t = e.sent()),
                                ((t = cc.instantiate(t)).parent = this.node),
                                t.setPosition(0, 0),
                                (this.curGuide = t.getComponent(p.default)),
                                n(),
                                [2]
                            );
                    }
                });
            });
        }),
        (v.prototype.show = function (e, t) {
            var n = this;
            this.setIsGuide(!0),
                this.curGuide
                    ? this.curGuide.show(e, t)
                    : this.loadGuideNode(function () {
                          n.curGuide.show(e, t);
                      });
        }),
        (v.prototype.checkGuide = function (e, t) {
            return !d.playerInfo.checkGuide(e) && (this.show(e, t), !0);
        }),
        (v.prototype.checkAllGuide = function (e) {
            if (this.isNeedCheck) {
                for (var t = d.playerInfo.getGuideStepCount(), n = !1, o = 0; o < t; o++) {
                    var i = 1 << (o + 1);
                    if (!d.playerInfo.checkGuide(i)) {
                        switch (((n = !0), i)) {
                            case c.choose:
                                this.checkGuide(c.choose, e[0].node);
                                break;
                            case c.place:
                                u.operEvent.emit({action: u.default.cellTouch, data: {cellIdx: 0, isChoose: !1}});
                                break;
                            case c.target:
                                u.operEvent.emit({action: u.default.guideTarget, data: {}});
                                break;
                            case c.deal:
                                u.operEvent.emit({action: u.default.guideDeal, data: {}});
                                break;
                            case c.choose1:
                                this.checkGuide(c.choose1, e[0].node);
                                break;
                            case c.place1:
                                u.operEvent.emit({action: u.default.cellTouch, data: {cellIdx: 0, isChoose: !1}});
                                break;
                            case c.choose2:
                                this.checkGuide(c.choose2, e[2].node);
                                break;
                            case c.place2:
                                u.operEvent.emit({action: u.default.cellTouch, data: {cellIdx: 2, isChoose: !1}});
                                break;
                            case c.deal1:
                                u.operEvent.emit({action: u.default.guideDeal, data: {}});
                        }
                        break;
                    }
                }
                n || u.operEvent.emit({action: u.default.targetAnim, data: {delayTime: 1}});
            } else console.log("no need checkAllGuide");
        }),
        (v.prototype.isNeedWeakGuide = function () {
            if ((0, this.isGuide)) return !1;
            if (!h.playerCoin.getIsCoinFirst()) return !1;
            var e = d.playerInfo.getStartTime(),
                t = new Date();
            return !(0 < e && 18e4 < t.getTime() - e);
        }),
        (v.prototype.showWeakMerge = function (e) {
            var t = this;
            this.isNeedMergeWeakGuide &&
                this.isNeedWeakGuide() &&
                (this.curGuide
                    ? this.curGuide.showWeakMerge(e)
                    : this.loadGuideNode(function () {
                          t.curGuide.showWeakMerge(e);
                      }));
        }),
        (v.prototype.showWeakDeal = function (e) {
            var t = this;
            this.isNeedDealWeakGuide &&
                this.isNeedWeakGuide() &&
                (this.curGuide
                    ? this.curGuide.showWeakDeal(e)
                    : this.loadGuideNode(function () {
                          t.curGuide.showWeakDeal(e);
                      }));
        }),
        (v.prototype.hideHand = function () {
            this.curGuide && this.curGuide.hideHand();
        }),
        (v.ins = null),
        (g = r([m, t("manager/guide-manager"), e], v)));
function v() {
    var e = (null !== y && y.apply(this, arguments)) || this;
    return (
        (e.curGuide = null),
        (e.isNeedCheck = !0),
        (e.isGuide = !1),
        (e.isNeedMergeWeakGuide = !0),
        (e.isNeedDealWeakGuide = !0),
        e
    );
}
n.GuideManager = e;
